/*
 * @Author: 汪军 624473119@qq.com
 * @Date: 2023-10-11 18:06:27
 * @LastEditors: 汪军 624473119@qq.com
 * @LastEditTime: 2023-10-20 09:34:26
 * @FilePath: \ekee-web\src\router\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { createRouter, createWebHashHistory } from "vue-router";
import HeaderAndFooterOutline from "../views/layout/HeaderAndFooterOutline.vue";
import HeaderOutline from "../views/layout/HeaderOutline.vue";
import MenuOutline from "../views/layout/MenuOutline.vue";
import { enterpriseCenterRouter } from "./end";
import { frontRouter } from "./front";
import { commonRouter } from "./common";
import enterpriseCenterApi from "@/api/enterprise-center";

const routes = [
  // 首页
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/home",
    name: "home",
    component: () => import("../views/home/home.vue"),
    meta: { title: "主页" },
  },
  //登录页
  {
    path: "/login",
    name: "login",
    component: () => import("../views/login/login.vue"),
    meta: { title: "登录页面" },
  },
  //注册页面
  {
    path: "/register",
    name: "register",
    component: () => import("../views/login/register.vue"),
    meta: { title: "注册页面" },
  },
  {
    path: "/",
    component: HeaderOutline,
    children: [
      {
        path: "/",
        component: MenuOutline,
        children: [...enterpriseCenterRouter],
      },
      ...commonRouter,
    ],
  },
  {
    path: "/",
    component: HeaderAndFooterOutline,
    children: [...frontRouter],
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

// 全局后置钩子
router.afterEach((to,from)=>{
	// 网站pv统计
  enterpriseCenterApi.commonPv({
    page: to.path
  })
})

// const originalPush = router.prototype.push
// router.prototype.push = function push(location) {
//   return originalPush.call(this, location).catch((err) => err)
// }

export default router;
